﻿using MiniBottles.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;

namespace MiniBottles.Controllers
{
  
    public class HomeController : Controller
    {
        private DataContext db = new DataContext();

        public ActionResult ChangeCulture(string lang, string returnUrl)
         {
              Session["Culture"] = new CultureInfo(lang);
              return Redirect(returnUrl);
         }


        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            ViewBag.VisitCounter = db.Visitors.Count();
            return View();
        }

        
        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        [ChildActionOnly]
        public ActionResult Menu()
        {
            ViewBag.Collections = db.DictCollection.Where(x => !x.IsDeleted && x.IsActive).OrderBy(x=> x.Name).ToList();
            
            return PartialView("_CollectionsMenu");
        }
        [ChildActionOnly]
        public ActionResult MainPageCollection()
        {
            var last = db.Bottles.Where(x => !x.DictCategory.IsDeleted && !x.IsDeleted).OrderByDescending(x => x.CreateDate).Take(3).ToList();
            ViewBag.BottleCount = db.Bottles.Where(x => !x.IsDeleted).Count();

            return PartialView("_MainPageCollection", last);
        }
        [ChildActionOnly]
        public ActionResult MainPageGuestBook()
        {
            var last = db.GuestBooks.Where(x => !x.IsDeleted).OrderByDescending(x=>x.CreateDate).Take(3).ToList();


            return PartialView("_MainPageGuestBook", last);
        }

        public ActionResult Gallery(int? page)
        {
            var galleries = db.Galleries.Where(x => !x.IsDeleted).OrderByDescending(x=>x.CreateDate);
            ViewBag.Galleries = galleries.ToPagedList<Gallery>(page ?? 1, 24);
            return View();
        }
    }
}
